//
//  TLShortStoryScrollTableViewCell.m
//  WXReader
//
//  Created by huaya on 2025/1/14.
//  Copyright © 2025 Andrew. All rights reserved.
//

#import "TLShortStoryScrollTableViewCell.h"
#import <AudioToolbox/AudioToolbox.h>

@interface TLShortStoryScrollTableViewCell()
@property (nonatomic, strong) TLLottieView *aniView;
@end

@implementation TLShortStoryScrollTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:TLShortStoryScrollStatusNotification object:nil];
    
    TLLottieView *aniView = [[TLLottieView alloc] initWithName:@"lottie_loading"];
    aniView.frame = self.lotttieView.bounds;
    aniView.loopAnimationCount = -1;
    [self.lotttieView addSubview:aniView];
    self.aniView = aniView;
    [aniView stop];

}
- (void)notificationAction:(NSNotification *)note{

    self.titleLab.text = [NSString stringWithFormat:@"%@",note.object];
    
    NSDictionary *userData = note.userInfo;
    
    if ([userData[@"ShowType"] isEqualToString:@"0"]) {
        //隐藏
        self.lotttieView.hidden = YES;
        [self.aniView stop];
        self.imgView.hidden = YES;
    }else if ([userData[@"ShowType"] isEqualToString:@"1"]) {
        [self.imgView setImage:[UIImage imageNamed:@"shzs_icon-up"]];
        self.lotttieView.hidden = YES;
        [self.aniView stop];
        self.imgView.hidden = NO;
    }else if ([userData[@"ShowType"] isEqualToString:@"2"]) {
        [self.imgView setImage:[UIImage imageNamed:@"shzs_icon-down"]];
        self.lotttieView.hidden = YES;
        [self.aniView stop];
        self.imgView.hidden = NO;
    }else if ([userData[@"ShowType"] isEqualToString:@"3"]) {
        
        if (self.lotttieView.hidden == NO) {
            return;
        }
        
        self.lotttieView.hidden = NO;
        
        [self.aniView play];
        
        self.imgView.hidden = YES;
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)refreshUI{
    
    [self.contentView setBackgroundColor:[[MKReaderCfg shared] bgColor]];
}
@end
